﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace SurfaceInteraction.UI.WP7
{
    public partial class SettingsPage : PhoneApplicationPage
    {
        public SettingsPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(SettingsPage_Loaded);
        }

        void SettingsPage_Loaded(object sender, RoutedEventArgs e)
        {
            PersonId.Text = Configuration.Id.ToString();
            //http://localhost:9102/
            IP.Text = Configuration.RemoteDesktop_ServiceURL.Replace("http://", "").Replace(":9102/", "");
        }

        void NavigationService_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            if (e.Content is SettingsPage)
            {
                PersonId.Text = Configuration.Id.ToString();
                IP.Text = Configuration.RemoteDesktop_ServiceURL;
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            byte id = 0;
            if (byte.TryParse(PersonId.Text.ToString(), out id))
            {
                //Conf.Id = id;
                Configuration.Id = id;
            }
            else
            {
                MessageBox.Show("You have to enter a nuber between 1 and 255", "Warning", MessageBoxButton.OK);
            }

            if (string.IsNullOrWhiteSpace(IP.Text.Trim()) == false)
            {
                Configuration.RemoteDesktop_ServiceURL = IP.Text.Trim();
                Configuration.FileExchange_ServiceURL = IP.Text.Trim();
            }


            NavigationService.GoBack();
        }
    }
}